<?php
//----------------------------------
//
// Alameda 0.1a (PSA)
//         Portal Script Adaptable
//
//----------------------------------
// Dario Diaz Videla 2004.
//----------------------------------
// Clase psa_form_grid
// Creacion de Grilla Dinamica de Muestra.
//----------------------------------
class psa_dina_grid {
   var $sql;
   var $sql2;
   var $desde;
   var $cantidad;
   var $procesa;
   var $linkbar;
   var $pagbar;

   function psa_dina_grid() {
      $this->sql    = "";
      $this->desde    = 0;
      $this->cantidad = 20;
      $this->procesa  = "";
      $this->linkbar  = "";
      $this->pagbar   = 0;
   }

   function muestra(){
      psa_dina_grid::gen();
   }

   function gen() {
      $dicci = new psa_diccionario;
      $pag = $this->pagbar;
      $maxpag = $this->cantidad;
      $ini = ($this->pagbar - 1) * $maxpag;
      $sql = $this->sql;
      include("inc/psa_conect.php");
      $result = mysql_query($this->sql2,$link);
      $row = mysql_fetch_array($result);
      $largo = $row[0];
      $paginas = intval($largo / $maxpag);
      if ($paginas < (($largo / $maxpag))){
         $paginas ++;
      }


      $sql=$sql." limit ".$ini.",".$this->cantidad;
      $result = mysql_query($sql,$link);

      $cant_camp =  mysql_num_fields($result) - $this->desde;
      $tab1 = new psa_tabla;
      $tab1->ancho = "100%";
      $tab1->alineacion = "center";

      if ($row = mysql_fetch_array($result)){
         $tab1->masfila($cant_camp+1);
         $sumlargo = 0;
         for ($i = $this->desde; $i < mysql_num_fields($result); $i++) {
              $sumlargo = $sumlargo + mysql_field_len($result,$i);
         }
         for ($i = $this->desde; $i < mysql_num_fields($result); $i++) {
              $campo = mysql_field_name($result, $i);
              $largo = ((mysql_field_len($result,$i)*100)/$sumlargo);
              $tab1->dato( ($i-$this->desde)+1, $dicci->traduce($campo,"E"), "center"," width=\"$largo%\"");
         }
         $tab1->dato( ($i-$this->desde)+1, "*", "center");
         do {
            $tab1->masfila($cant_camp+1);
            for( $i=$this->desde; $i < mysql_num_fields($result); $i++ ) {
               $largo = ((mysql_field_len($result,$i)*100)/$sumlargo);
               $tab1->dato( ($i-$this->desde)+1, $row[$i], "center"," width=\"$largo%\"");
            }
            $tab1->dato( ($i-$this->desde)+1, "<form name='form_grid' method='post' action='$this->procesa' enctype='multipart/form-data'><input type='submit' name='Envio' value=' - ' ><input type='hidden' name='id' value='".$row["id"]." ' ></form>", "center");
         } while ($row = mysql_fetch_array($result));
      }
      $tab1->muestra();

      $form1 = new psa_formulario;

      $despnav = 9;
      $ininav = max(1,$pag-intval($despnav/2));
      $finnav = min($paginas,$pag+intval($despnav/2));
      if (($finnav-$ininav+1) < $despnav) {
         $ininav = max(1,$ininav-($despnav-($finnav-$ininav+1)));
         $finnav = min($paginas,$finnav+($despnav-($finnav-$ininav+1)));
      }
      $nav1 = new psa_nav_bar;
      $nav1->cant=$paginas;
      $nav1->alineacion="center";
      $nav1->conector="&";
      $nav1->inicio($ininav);
      $nav1->fin($finnav);
      $nav1->actual($pag);
      $nav1->pagina($this->linkbar);
      $nav1->muestra();

      mysql_close($link);
   }
}
?>
